<template>
  <div class="container">
    <el-row>
      <el-form :model="formInline" @keyup.enter.native="search">
        <el-col :span="6" align="left">
          <el-form-item :label="$t('m.notice.noticenumber')" :label-width="formLabelWidth">
            <el-input maxlength="20" show-word-limit v-model="formInline.noticenumber"></el-input>
          </el-form-item>
          <el-form-item :label="$t('m.in.suppliername')" :label-width="formLabelWidth">
            <el-input maxlength="20" show-word-limit v-model="formInline.suppliername"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" align="left">
          <el-form-item :label="$t('m.in.ordernumber')" :label-width="formLabelWidth">
            <el-input maxlength="30" show-word-limit v-model="formInline.ordernumber"></el-input>
          </el-form-item>
          <el-form-item label="SKU" :label-width="formLabelWidth">
            <el-input maxlength="20" show-word-limit v-model="formInline.productspeccode"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" align="left">
          <el-row>
            <el-form-item :label="$t('m.in.planeddate')" :label-width="formLabelWidth">
              <el-col :span="11">
                <el-form-item>
                  <el-date-picker @change="checkDate" type="date" :placeholder="$t('m.in.choosedate')" v-model="formInline.startdate" style="width: 100%;"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col class="line" :span="2" align="center">-</el-col>
              <el-col :span="11">
                <el-form-item prop="enddate">
                  <el-date-picker @change="checkDate" value-format="timestamp" type="date" :placeholder="$t('m.in.choosedate')" v-model="formInline.enddate" style="width: 100%;"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-form-item>
            <el-col :span="12">
              <el-form-item :label="$t('m.in.suppliercode')" :label-width="formLabelWidth">
                <el-input maxlength="20" show-word-limit v-model="formInline.suppliercode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('m.in.erpordercode')" :label-width="formLabelWidth">
                <el-input maxlength="20" show-word-limit v-model="formInline.erpordercode"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="6" align="left">
          <el-form-item :label="$t('m.state')" :label-width="formLabelWidth">
            <el-select v-model="formInline.state" :placeholder="$t('m.choose')">
              <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" align="right">
          <el-form-item>
            <el-button @click="search" v-if="hasPermission('search')">{{$t('m.query')}}</el-button>
            <el-button type="primary" @click="increase" v-if="hasPermission('add')">{{$t('m.add')}}</el-button>
            <el-button @click="toSign" v-if="hasPermission('sign')">{{$t('m.sigin.sigin')}}</el-button>
            <el-button @click="clickConfirm" v-if="hasPermission('confirm')">{{$t('m.in.confirm')}}</el-button>
            <el-button @click="clickCancel" v-if="hasPermission('cancel')">{{$t('m.arrivalnotice.cancel')}}</el-button>
            <el-button @click="print" v-if="hasPermission('print')">{{$t('m.print')}}</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div class="ellipse"></div>
    <el-table ref="table" stripe empty-text fits class="single-select-table" :data="tableData" :row-style="tableRowStyle" :row-class-name="tableRowClassName" @row-click="rowClick" @selection-change="handleSingleSelectionChange" v-loading="tableLoading">
      <el-table-column align="center" type="selection" width="55"></el-table-column>
      <el-table-column align="center" type="index" :label="$t('m.index')" width="50"></el-table-column>
      <el-table-column align="center" prop="noticenumber" :label="$t('m.notice.noticenumber')">
        <template slot-scope="scope">
          <template v-if="hasPermission('table-notice')">
            <el-button type="text" @click.stop="arrivalOpen(scope.row)">{{scope.row.noticenumber}}</el-button>
          </template>
          <template v-else>{{scope.row.noticenumber}}</template>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="ordernumber" :label="$t('m.in.ordernumber')"></el-table-column>
      <el-table-column align="center" prop="erpordercode" :label="$t('m.in.erpordercode')"></el-table-column>
      <el-table-column :label="$t('m.state')" align="center">
        <template slot-scope="scope">
          <span>{{options(scope.row.state)}}</span>
          <el-tooltip effect="light" placement="right" v-if="scope.row.state==2">
            <div slot="content">{{scope.row.auditopinion}}</div>
            <span style="font-size:18px;color:#409EFF" class="el-icon-s-comment"></span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="suppliername" :label="$t('m.in.suppliername')" width="140"></el-table-column>
      <el-table-column align="center" :label="$t('m.in.warehouse')">
        <span>{{$store.state.basicInfo.warehouseInfo.name}}</span>
      </el-table-column>
      <el-table-column align="center" prop="typename" :label="$t('m.in.typename')"></el-table-column>
      <el-table-column align="center" prop="creator" :label="$t('m.creator')" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="createdate" :label="$t('m.createdate')"></el-table-column>
      <el-table-column align="center" prop="modifier" :label="$t('m.modifier')" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="modifydate" :label="$t('m.modifydate')"></el-table-column>
      <el-table-column :label="$t('m.operation')" width="150" align="center">
        <template slot-scope="scope">
          <el-button v-if="scope.row.state==1&&hasPermission('table-examine')" type="primary" @click.stop="checkOpen(scope.row)" size="mini">{{$t('m.in.check')}}</el-button>
          <el-button v-if="(scope.row.state==1||scope.row.state==2)&&hasPermission('table-edit')" type="primary" @click.stop="open(scope.row)" size="mini">{{$t('m.edit')}}</el-button>
          <el-button size="mini" v-if="[7].includes(scope.row.state)&&hasPermission('table-print')" @click="printPdf(scope.row)">{{$t('m.print')}}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination background layout="sizes, prev, pager, next, jumper" :page-sizes="pageSizeList" :page-size="rowSize" :current-page="page" :total="totalRows" @current-change="currentChangeInitFn" @size-change="handleSizeChangeInitFn"></el-pagination>
    <!-- 到货通知编辑 dialog 开始 -->
    <el-dialog :close-on-click-modal="false" width="1200px" :title="$t('m.in.arrivalnotice')" :visible.sync="dialogFormVisible">
      <el-form align="left" :rules="ruleFormEdit" ref="ruleFormEdit" size="mini" :model="form">
        <el-row :gutter="10">
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.notice.noticenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.noticenumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.noticenumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.consignor')" :label-width="formLabelWidth" prop="arrivalnoticeDto.consignorname">
              <el-select @change="setConsignor" filterable v-model="form.arrivalnoticeDto.consignorname" :placeholder="$t('m.choose')">
                <el-option v-for="item in consignor" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliverycompany')" :label-width="formLabelWidth">
              <el-input maxlength="20" show-word-limit size="mini" v-model="form.arrivalnoticeDto.deliverycompany" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.contact')" :label-width="formLabelWidth" prop="arrivalnoticeDto.contact">
              <el-input maxlength="20" show-word-limit size="mini" v-model="form.arrivalnoticeDto.contact" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.ordernumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.ordernumber">
              <el-input maxlength="20" @input="check_num()" show-word-limit size="mini" v-model="form.arrivalnoticeDto.ordernumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.suppliername')" :label-width="formLabelWidth" prop="arrivalnoticeDto.suppliername">
              <el-select @change="setSupplier" filterable v-model="form.arrivalnoticeDto.suppliername" :placeholder="$t('m.choose')">
                <el-option v-for="item in supplier" :key="item.supplierid" :label="item.suppliername" :value="item.supplierid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.platenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.platenumber">
              <el-input maxlength="20" show-word-limit size="mini" v-model="form.arrivalnoticeDto.platenumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.planeddate')" :label-width="formLabelWidth" prop="arrivalnoticeDto.planeddate">
              <el-date-picker :picker-options="pickerOptions" value-format="yyyy-MM-dd" size="mini" v-model="form.arrivalnoticeDto.planeddate" type="date" :placeholder="$t('m.in.choosedate')" style="width: 100%;padding-right:0"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.warehouse')" :label-width="formLabelWidth" prop="arrivalnoticeDto.warehouseid">
              <el-input size="mini" v-model="$store.state.basicInfo.warehouseInfo.name" disabled></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.typename')" :label-width="formLabelWidth" prop="arrivalnoticeDto.typename">
              <el-select @change="setType" v-model="form.arrivalnoticeDto.typename" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in arrivaltype" :key="index" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliveryman')" :label-width="formLabelWidth" prop="arrivalnoticeDto.deliveryman">
              <el-input maxlength="20" show-word-limit size="mini" v-model="form.arrivalnoticeDto.deliveryman" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('m.remark')" :label-width="formLabelWidth" prop="arrivalnoticeDto.remark">
              <el-input v-model="form.arrivalnoticeDto.remark" autocomplete="off" type="textarea" maxlength="100" show-word-limit></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="section">
          <template>
            <el-table :data="form.arrivalnoticedetailList" border empty-text size="mini">
              <el-table-column :label="$t('m.index')" width="50" align="center">
                <template slot-scope="scope">{{scope.$index+1}}</template>
              </el-table-column>
              <el-table-column label="SKU" width="180" align="center">
                <template slot-scope="scope">
                  <el-form-item prop="productspeccode">
                    <el-input maxlength="20" show-word-limit @input="func1" @blur="blur1&&getSkuBlur(scope.$index,form)" @keyup.enter.native="getSkuEnter(scope.$index,form)" v-model="scope.row.productspeccode" size="mini" required></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="SupplierCode" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.suppliercode">{{scope.row.suppliercode}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productname')" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productname">{{scope.row.productname}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productspec')" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productspec">{{scope.row.productspec}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.plannedquantity')" align="center">
                <template slot-scope="scope">
                  <el-form-item :prop="'arrivalnoticedetailList.' + scope.$index + '.plannedquantity'" :rules="ruleFormEdit.num">
                    <el-input @input="positiveInt2('plannedquantity',scope.$index)" maxlength="10" show-word-limit v-model="scope.row.plannedquantity" size="mini"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.operation')" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <el-button size="mini" type="danger" @click="editDelete(scope.$index, scope.row)">{{$t('m.delete')}}</el-button>
                  </el-form-item>
                </template>
              </el-table-column>
            </el-table>
            <el-row type="flex" :gutter="20" style=" margin-left: 0px; margin-right: 0px;">
              <el-col :span="3">
                <el-button type="primary" size="mini" @click="editAddProduct()">{{$t('m.in.addproduct')}}</el-button>
              </el-col>
            </el-row>
          </template>
        </div>
      </el-form>
      <div class="btns">
        <el-button size="mini" @click="editCancel">{{$t('m.cancel')}}</el-button>
        <el-button size="mini" type="primary" @click="change()">{{$t('m.confirm')}}</el-button>
      </div>
    </el-dialog>
    <!-- 到货通知编辑 dialog 结束 -->
    <!-- 确认到货&&表格：到货通知单 dialog 开始 -->
    <el-dialog width="1200px" :title="$t('m.in.arrivalnotice')" :visible.sync="dialogFormVisible3">
      <el-form align="left" :rules="ruleFormEdit" ref="ruleFormEdit" size="mini" :model="form">
        <el-row :gutter="10">
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.notice.noticenumber')" :label-width="formLabelWidth" prop="noticenumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.noticenumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.consignor')" :label-width="formLabelWidth" prop="consignorname">
              <el-select disabled @change="setConsignor" v-model="form.arrivalnoticeDto.consignorname" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in consignor" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliverycompany')" :label-width="formLabelWidth">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.deliverycompany" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.contact')" :label-width="formLabelWidth" prop="contact">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.contact" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.ordernumber')" :label-width="formLabelWidth" prop="ordernumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.ordernumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.suppliername')" :label-width="formLabelWidth" prop="suppliername">
              <el-select disabled @change="setSupplier" v-model="form.arrivalnoticeDto.suppliername" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in supplier" :key="index" :label="item.suppliername" :value="item.supplierid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.platenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.platenumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.platenumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.planeddate')" :label-width="formLabelWidth">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.planeddate" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.warehouse')" :label-width="formLabelWidth" prop="warehouseid">
              <el-select disabled v-model="form.arrivalnoticeDto.warehouseid" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in warehouse" :key="index" :label="item.warehousename" :value="item.warehouseid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.typename')" :label-width="formLabelWidth" prop="typename">
              <el-select disabled @change="setType" v-model="form.arrivalnoticeDto.typename" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in arrivaltype" :key="index" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliveryman')" :label-width="formLabelWidth" prop="deliveryman">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.deliveryman" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('m.remark')" :label-width="formLabelWidth" prop="remark">
              <el-input maxlength="100" show-word-limit disabled type="textarea" v-model="form.arrivalnoticeDto.remark" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="section">
          <template>
            <el-table :data="form.arrivalnoticedetailList" border empty-text size="mini">
              <el-table-column :label="$t('m.index')" type="index" width="50" align="center"></el-table-column>
              <el-table-column label="SKU" width="180" prop="productspeccode" align="center"></el-table-column>
              <el-table-column label="SupplierCode" width="120" prop="suppliercode" align="center"></el-table-column>
              <el-table-column :label="$t('m.in.productname')" prop="productname" align="center"></el-table-column>
              <el-table-column :label="$t('m.in.productspec')" prop="productspec" align="center"></el-table-column>
              <el-table-column :label="$t('m.in.plannedquantity')" prop="plannedquantity" align="center"></el-table-column>
              <el-table-column :label="$t('m.in.actual')" prop="actualquantity" align="center"></el-table-column>
              <el-table-column :label="$t('m.sigin.amount')" prop="signedquantity" align="center"></el-table-column>

              <el-table-column :label="$t('m.operation')" align="center">
                <template slot-scope="scope">
                  <template v-if="form.arrivalnoticeDto.state>3">
                    <el-button type="primary" size="mini" @click="triggerSigning(scope.$index,scope.row)">{{$t('m.sigin.result')}}</el-button>
                  </template>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </div>
      </el-form>
      <div class="btns">
        <el-button v-if="opt==='confirm'" size="mini" @click="confirm">{{$t('m.confirm')}}</el-button>
        <el-button size="mini" @click="dialogFormVisible3=false;opt=''">{{$t('m.close')}}</el-button>
      </div>
    </el-dialog>
    <!-- 确认到货&&表格：到货通知单 dialog 结束 -->

    <!-- 到货通知新增 dialog 开始 -->
    <el-dialog :close-on-click-modal="false" @close="closeAddDialog" width="1200px" :title="$t('m.add')+$t('m.in.arrivalnotice')" :visible.sync="dialogFormVisible1">
      <el-form align="left" :rules="ruleFormAdd" ref="ruleFormAdd" size="mini" :model="increaseForm">
        <el-row :gutter="10">
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.consignor')" :label-width="formLabelWidth" prop="arrivalnoticeDto.consignorname">
              <el-select @change="setConsignor" filterable v-model="increaseForm.arrivalnoticeDto.consignorname" :placeholder="$t('m.choose')">
                <el-option v-for="item in consignor" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliverycompany')" :label-width="formLabelWidth" prop="arrivalnoticeDto.deliverycompany">
              <el-input maxlength="20" show-word-limit size="mini" v-model="increaseForm.arrivalnoticeDto.deliverycompany" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.contact')" :label-width="formLabelWidth" prop="arrivalnoticeDto.contact">
              <el-input maxlength="20" show-word-limit size="mini" v-model="increaseForm.arrivalnoticeDto.contact" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.planeddate')" :label-width="formLabelWidth" prop="arrivalnoticeDto.planeddate">
              <el-date-picker :picker-options="pickerOptions" value-format="yyyy-MM-dd" size="mini" v-model="increaseForm.arrivalnoticeDto.planeddate" type="date" :placeholder="$t('m.in.choosedate')" style="width: 100%;padding-right:0"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.ordernumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.ordernumber">
              <el-input maxlength="20" show-word-limit @input="check_num_add()" size="mini" v-model="increaseForm.arrivalnoticeDto.ordernumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.suppliername')" :label-width="formLabelWidth" prop="arrivalnoticeDto.suppliername">
              <el-select @change="setSupplier" filterable v-model="increaseForm.arrivalnoticeDto.suppliername" :placeholder="$t('m.choose')">
                <el-option v-for="item in supplier" :key="item.supplierid" :label="item.suppliername" :value="item.supplierid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.platenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.platenumber">
              <el-input maxlength="20" show-word-limit size="mini" v-model="increaseForm.arrivalnoticeDto.platenumber" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.warehouse')" :label-width="formLabelWidth" prop="arrivalnoticeDto.warehousename">
              <el-input size="mini" v-model="$store.state.basicInfo.warehouseInfo.name" disabled></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.typename')" :label-width="formLabelWidth" prop="arrivalnoticeDto.typename">
              <el-select @change="setType" v-model="increaseForm.arrivalnoticeDto.typename" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in arrivaltype" :key="index" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliveryman')" :label-width="formLabelWidth" prop="arrivalnoticeDto.deliveryman">
              <el-input maxlength="20" show-word-limit size="mini" v-model="increaseForm.arrivalnoticeDto.deliveryman" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('m.remark')" :label-width="formLabelWidth" prop="arrivalnoticeDto.remark">
              <el-input maxlength="100" show-word-limit type="textarea" v-model="increaseForm.arrivalnoticeDto.remark" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="section">
          <template>
            <el-table :data="increaseForm.arrivalnoticedetailList" border empty-text size="mini">
              <el-table-column :label="$t('m.index')" width="50" align="center">
                <template slot-scope="scope">{{scope.$index+1}}</template>
              </el-table-column>
              <el-table-column label="SKU" width="180" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <el-input
                      maxlength="20"
                      show-word-limit
                      @input="func1"
                      @blur="blur1&&getSkuBlur(scope.$index,increaseForm)"
                      @keyup.enter.native="getSkuEnter(scope.$index,increaseForm)"
                      v-model="scope.row.productspeccode"
                      size="mini"
                      required
                    ></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="SupplierCode" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.suppliercode">{{scope.row.suppliercode}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productname')" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productname">{{scope.row.productname}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productspec')" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productspec">{{scope.row.productspec}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.plannedquantity')" align="center">
                <template slot-scope="scope">
                  <el-form-item :prop="'arrivalnoticedetailList.' + scope.$index + '.plannedquantity'" :rules="ruleFormAdd.num">
                    <el-input @input="positiveInt('plannedquantity',scope.$index)" maxlength="10" show-word-limit v-model="scope.row.plannedquantity" size="mini"></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.operation')" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">{{$t('m.delete')}}</el-button>
                  </el-form-item>
                </template>
              </el-table-column>
            </el-table>
            <el-row type="flex" :gutter="20" style=" margin-left: 0px; margin-right: 0px;">
              <el-col :span="3">
                <div class="grid-content bg-purple">
                  <el-button type="primary" size="mini" @click="addProduct()">{{$t('m.in.addproduct')}}</el-button>
                </div>
              </el-col>
            </el-row>
          </template>
        </div>
      </el-form>
      <div class="btns">
        <el-button size="mini" @click="dialogFormVisible1 = false">{{$t('m.cancel')}}</el-button>
        <el-button size="mini" type="primary" @click="handIncrease()">{{$t('m.confirm')}}</el-button>
      </div>
    </el-dialog>
    <!-- 到货通知新增 dialog 结束 -->

    <!-- 到货通知审核 dialog 开始 -->
    <el-dialog :close-on-click-modal="false" @close="closeDialog" width="1200px" :title="$t('m.in.arrivalnotice')+$t('m.in.check')" :visible.sync="dialogFormVisible2">
      <el-form align="left" :rules="ruleFormEdit" ref="ruleFormEdit" size="mini" :model="form">
        <el-row :gutter="10">
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.notice.noticenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.noticenumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.noticenumber" autocomplete="off"></el-input>
              <!-- <span>{{form.noticenumber}}</span> -->
            </el-form-item>
            <el-form-item :label="$t('m.in.consignor')" :label-width="formLabelWidth" prop="arrivalnoticeDto.consignorname">
              <el-select disabled @change="setConsignor" v-model="form.arrivalnoticeDto.consignorname" :placeholder="$t('m.choose')">
                <el-option v-for="item in consignor" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliverycompany')" :label-width="formLabelWidth">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.deliverycompany" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.contact')" :label-width="formLabelWidth" prop="arrivalnoticeDto.contact">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.contact" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.ordernumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.ordernumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.ordernumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.suppliername')" :label-width="formLabelWidth" prop="arrivalnoticeDto.suppliername">
              <el-select disabled @change="setSupplier" v-model="form.arrivalnoticeDto.suppliername" :placeholder="$t('m.choose')">
                <el-option v-for="item in supplier" :key="item.supplierid" :label="item.suppliername" :value="item.supplierid"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.platenumber')" :label-width="formLabelWidth" prop="arrivalnoticeDto.platenumber">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.platenumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.planeddate')" :label-width="formLabelWidth">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.planeddate" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item :label="$t('m.in.warehouse')" :label-width="formLabelWidth" prop="arrivalnoticeDto.warehouseid">
              <el-input size="mini" v-model="$store.state.basicInfo.warehouseInfo.name" disabled></el-input>
            </el-form-item>
            <el-form-item :label="$t('m.in.typename')" :label-width="formLabelWidth" prop="arrivalnoticeDto.typename">
              <el-select disabled @change="setType" v-model="form.arrivalnoticeDto.typename" :placeholder="$t('m.choose')">
                <el-option v-for="(item,index) in arrivaltype" :key="index" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('m.in.deliveryman')" :label-width="formLabelWidth" prop="arrivalnoticeDto.deliveryman">
              <el-input disabled size="mini" v-model="form.arrivalnoticeDto.deliveryman" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('m.remark')" :label-width="formLabelWidth" prop="arrivalnoticeDto.remark">
              <el-input disabled type="textarea" v-model="form.arrivalnoticeDto.remark" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="section">
          <template>
            <el-table :data="form.arrivalnoticedetailList" stripe empty-text size="mini">
              <el-table-column :label="$t('m.index')" width="50" align="center">
                <template slot-scope="scope">{{scope.$index+1}}</template>
              </el-table-column>
              <el-table-column label="SKU" width="180" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <el-input disabled @input="getSku(scope.$index)" v-model="scope.row.productspeccode" size="mini" required></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="SupplierCode" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.suppliercode">{{scope.row.suppliercode}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productname')" width="120" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productname">{{scope.row.productname}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.productspec')" align="center">
                <template slot-scope="scope">
                  <el-form-item>
                    <span :v-model="scope.row.productspec">{{scope.row.productspec}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column :label="$t('m.in.plannedquantity')" align="center">
                <template slot-scope="scope">
                  <el-input disabled v-model.number="scope.row.plannedquantity" size="mini" required></el-input>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </div>
      </el-form>
      <el-form align="left" :rules="checkFormRule" ref="checkForm" :model="checkForm">
        <el-form-item :label="$t('m.in.result')" :label-width="formLabelWidth" prop="state">
          <el-radio-group v-model="checkForm.state">
            <el-radio label="1">
              <span style="font-size:10px;">{{$t('m.in.pass')}}</span>
            </el-radio>
            <el-radio label="0">
              <span style="font-size:10px;">{{$t('m.in.state2')}}</span>
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="checkForm.state==0" :label="$t('m.notice.opinion')" :label-width="formLabelWidth" prop="auditopinion">
          <el-input type="textarea" maxlength="100" show-word-limit v-model="checkForm.auditopinion"></el-input>
        </el-form-item>
        <el-form-item v-else :label="$t('m.notice.opinion')" :label-width="formLabelWidth">
          <el-input type="textarea" maxlength="100" show-word-limit v-model="checkForm.auditopinion"></el-input>
        </el-form-item>
        <div class="btns">
          <el-button size="mini" @click="editCancel">{{$t('m.cancel')}}</el-button>
          <el-button size="mini" type="primary" @click="check()">{{$t('m.confirm')}}</el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 到货通知审核 dialog 结束 -->

    <!-- 理货功能dialog start -->
    <signingAddPopup
      v-if="signingAddPopupVisible"
      :popupVisible="signingAddPopupVisible"
      :arrivalnoticeDetail="arrivalnoticeArg"
      @close="signingAddPopupVisible=false"
    ></signingAddPopup>
    <!-- 理货功能dialog end -->
  </div>
</template>

<script>
import common from '@/utils/common'
import { getLodop } from '@/utils/LodopFuncs'
export default {
  name:'arrivalNotice',
  components:{
    signingAddPopup:() => import('@/components/arrivalNotice/signing-add-popup')
  },
  data(){
    return {
      blur1:true,
      blur2:true, //判断blur事件是否需要触发
      code:'',
      count:null,
      formInline:{},
      tableData:[],
      dialogFormVisible:false,
      dialogFormVisible1:false,
      dialogFormVisible2:false,
      dialogFormVisible3:false,
      isClick:true,
      editClick:false,
      warehouse:[],
      consignor:[],
      supplier:[],
      form:{
        arrivalnoticeDto:{
          arrivalnoticeid:null,
          auditopinion:'',
          consignorid:null,
          consignorname:'',
          contact:'',
          createdate:null,
          createid:null,
          creator:'',
          deliverycompany:'',
          deliveryman:'',
          noticenumber:'',
          ordernumber:'',
          platenumber:'',
          remark:'',
          state:null,
          statename:'',
          supplierid:null,
          suppliername:'',
          typeid:null,
          typename:'',
          warehouseid:this.$store.state.basicInfo.warehouseInfo.id,
          planeddate:null
        },
        arrivalnoticedetailList:[
          {
            arrivalnoticedetailid:null,
            plannedquantity:null,
            productname:'',
            productspec:'',
            productspeccode:'',
            suppliercode:null,
            expirationnum:null,
            limitationofreceipt:null
          }
        ]
      },
      increaseForm:{
        arrivalnoticeDto:{
          arrivalnoticeid:null,
          auditopinion:'',
          consignorid:null,
          consignorname:'',
          contact:'',
          createdate:null,
          createid:null,
          creator:'',
          deliverycompany:'',
          deliveryman:'',
          noticenumber:'',
          ordernumber:'',
          platenumber:'',
          remark:'',
          state:null,
          statename:'',
          supplierid:null,
          suppliername:'',
          typeid:null,
          typename:'',
          warehouseid:this.$store.state.basicInfo.warehouseInfo.id,
          planeddate:null
        },
        arrivalnoticedetailList:[
          {
            arrivalnoticedetailid:null,
            plannedquantity:null,
            productname:'',
            productspec:'',
            productspeccode:'',
            suppliercode:null,
            expirationnum:null,
            limitationofreceipt:null
          }
        ]
      },
      checkForm:{
        auditopinion:'',
        state:null
      },
      formLabelWidth:'140px',
      type:'', //到货类型
      pickerOptions:{
        // 限制时间不可选择今天以前的
        disabledDate(time){
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
        }
      },
      opt:'',
      row:{},
      activeNoticenumber:'', // 当前激活的通知单号
      arrivalnoticeArg:{},
      signingAddPopupVisible:false // 控制理货功能dialog显示隐藏
    }
  },
  watch:{
    dialogFormVisible(){
      this.init()
    }
  },
  computed:{
    // 1 待审核 2 不通过 3 已审核 4 待签收 5 部分理货 6全部理货 7已完成 20已取消
    stateOptions(){
      return [
        { label:this.$t('m.all'), value:'' },
        { label:this.$t('m.in.state1'), value:1 },
        { label:this.$t('m.in.state2'), value:2 },
        { label:this.$t('m.in.state6'), value:3 },
        { label:this.$t('m.in.state4'), value:5 },
        { label:this.$t('m.in.state10'), value:6 },
        { label:this.$t('m.in.state11'), value:7 },
        { label:this.$t('m.in.state20'), value:20 }
      ]
    },
    arrivaltype(){
      return [
        { value:'1', label:'订单到货' }, // label:this.$t('m.in.arrivaltype1')
        { value:'2', label:'第三方到货' }, // label:this.$t('m.in.arrivaltype2')
        { value:'3', label:'退货到货' }, // label:this.$t('m.in.arrivaltype3')
        { value:'4', label:'其他' } // label:this.$t('m.in.other')

      ]
    },
    checkFormRule(){
      this.$nextTick(() => {
        this.$refs.checkForm.clearValidate()
      })
      return {
        state:[
          {
            required:true,
            message:this.$t('m.choose') + this.$t('m.in.result'),
            trigger:'blur'
          }
        ],
        auditopinion:[
          {
            required:true,
            message:this.$t('m.enter') + this.$t('m.notice.opinion'),
            trigger:'blur'
          }
        ]
      }
    },
    ruleFormAdd(){
      this.$nextTick(() => {
        this.$refs.ruleFormAdd.clearValidate()
      })
      let onlyNumber = (rule, value, callback) => {
        if (!/^\+?[1-9]\d*$/.test(value)){
          return callback(new Error(this.$t('m.onlynumber')))
        }
        callback()
      }
      return {
        num:[
          {
            required:true,
            message:this.$t('m.enter'),
            trigger:'blur'
          },
          { validator:onlyNumber, trigger:'blur' }
        ],
        arrivalnoticeDto:{
          warehouseid:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.warehouse'),
              trigger:'change'
            }
          ],
          consignorname:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.consignor'),
              trigger:'change'
            }
          ],
          ordernumber:[
            {
              required:true,
              message:this.$t('m.enter') + this.$t('m.in.ordernumber'),
              trigger:'blur'
            },
            {
              max:20,
              message:this.$t('m.in.ordernumber') + this.$t('m.check.number20')
            }
          ],
          suppliername:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.suppliername'),
              trigger:'change'
            }
          ],
          typename:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.typename'),
              trigger:'change'
            }
          ],
          planeddate:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.planeddate'),
              trigger:'change'
            }
          ]
        }
      }
    },

    ruleFormEdit(){
      let onlyNumber = (rule, value, callback) => {
        if (!/^\+?[1-9]\d*$/.test(value)){
          return callback(new Error(this.$t('m.onlynumber')))
        }
        callback()
      }
      return {
        num:[
          {
            required:true,
            message:this.$t('m.enter'),
            trigger:'blur'
          },
          { validator:onlyNumber, trigger:'blur' }
        ],
        arrivalnoticeDto:{
          warehouseid:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.warehouse'),
              trigger:'change'
            }
          ],
          consignorname:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.consignor'),
              trigger:'change'
            }
          ],
          ordernumber:[
            {
              required:true,
              message:this.$t('m.enter') + this.$t('m.in.ordernumber'),
              trigger:'blur'
            }
          ],
          suppliername:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.suppliername'),
              trigger:'change'
            }
          ],
          typename:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.typename'),
              trigger:'change'
            }
          ],
          planeddate:[
            {
              required:true,
              message:this.$t('m.choose') + this.$t('m.in.planeddate'),
              trigger:'change'
            }
          ]
        }
      }
    }
  },
  methods:{
    search(){
      this.page = 1
      this.init()
    },
    init(){
      this.tableLoading = true
      this.$axios({
        method:'get',
        url:'/arrivalnotice/page',
        params:Object.assign({}, this.formInline, {
          page:this.page,
          rows:this.rowSize
        })
      }).then(({ data }) => {
        for (let i = 0;i < data.records.length;i++){
          data.records[i].createdate = common.timestampToTime(
            data.records[i].createdate
          )

          if (data.records[i].modifydate){
            data.records[
              i
            ].modifydate = common.timestampToTime(
              data.records[i].modifydate
            )
          } else {
            data.records[i].modifydate = '- -'
          }
        }
        this.tableData = data.records
        this.totalRows = data.total
        setTimeout(()=>this.tableLoading=false,500)
      })
    },
    checkOpen(row){
      this.getConsignor()
      this.$axios({
        method:'get',
        url:`/arrivalnotice/${row.arrivalnoticeid}`
      }).then(({ data }) => {
        this.form = data
        this.form.arrivalnoticeDto.planeddate = common.timestampSimple(
          data.arrivalnoticeDto.planeddate
        )
        this.dialogFormVisible2 = true
      })
    },
    open(row){
      this.supplier = []
      this.consignor = []
      this.warehouse = []
      this.getSupplier()
      this.getWarehouse()
      this.openInfo(row)
      this.getConsignor()
      this.dialogFormVisible = true
    },
    arrivalOpen(row){
      this.openInfo(row)
      this.activeNoticenumber = row.noticenumber
      this.dialogFormVisible3 = true
    },
    openInfo(row){
      this.getConsignor()
      this
        .$axios({
          method:'get',
          url:`/arrivalnotice/${row.arrivalnoticeid}`
        })
        .then(({ data }) => {
          this.checkForm.auditopinion = ''
          this.form = data
          this.form.arrivalnoticeDto.planeddate = common.timestampSimple(
            data.arrivalnoticeDto.planeddate
          )
        })
    },
    change(){
      this.$refs['ruleFormEdit'].validate(valid => {
        if (valid){
          let that = this
          let firstClass = that.form.arrivalnoticedetailList
          for (let i = 0;i < firstClass.length;i++){
            if (!firstClass[i].productspeccode){
              return that.$message({
                showClose:true,
                message:this.$t('m.enter') + 'SKU',
                type:'warning',
                duration:1000
              })
            } else {
              if (
                !firstClass[i].plannedquantity ||
                firstClass[i].plannedquantity < 1
              ){
                return that.$message({
                  showClose:true,
                  message:that.$t('m.enter') + that.$t('m.in.plannedquantity'),
                  type:'warning',
                  duration:1000
                })
              }
            }
          }
          let id = that.form.arrivalnoticeDto.arrivalnoticeid
          let obj = that.form
          that
            .$axios({
              method:'put',
              url:`/arrivalnotice/${id}`,
              data:obj
            })
            .then(() => {
              that.$message({
                showClose:true,
                message:that.$t('m.editSuccess'),
                type:'success',
                duration:1000
              })
              that.dialogFormVisible = false
              that.page = 1
              that.init()
            })
        }
      })
    },
    check(){
      this.$refs['checkForm'].validate(valid => {
        if (valid){
          if (!this.checkForm.auditopinion && this.checkForm.state === '0'){
            this.$message({
              showClose:true,
              message:this.$t('m.enter') + this.$t('m.notice.opinion'),
              type:'error',
              duration:1000
            })
          } else {
            let id = this.form.arrivalnoticeDto.arrivalnoticeid
            this
              .$axios({
                method:'put',
                url:`/arrivalnotice/check/${id}`,
                data:this.checkForm
              })
              .then(() => {
                this.$message({
                  showClose:true,
                  message:this.$t('m.quality.success'),
                  type:'success',
                  duration:1000
                })
                this.dialogFormVisible2 = false
                this.page = 1
                this.init()
              })
          }
        }
      })
    },
    increase(){
      this.dialogFormVisible1 = true
      this.supplier = []
      this.consignor = []
      this.warehouse = []
      this.getSupplier()
      this.getWarehouse()
      this.getConsignor()
    },
    handIncrease(){
      this.$refs['ruleFormAdd'].validate(valid => {
        if (valid){
          let that = this
          let firstClass = that.increaseForm.arrivalnoticedetailList
          for (let i = 0;i < firstClass.length;i++){
            if (!firstClass[i].productspeccode){
              return that.$message({
                showClose:true,
                message:this.$t('m.enter') + 'SKU',
                type:'warning',
                duration:1000
              })
            } else {
              if (!firstClass[i].plannedquantity){
                return that.$message({
                  showClose:true,
                  message:this.$t('m.enter') + this.$t('m.in.plannedquantity'),
                  type:'warning',
                  duration:1000
                })
              } else if (firstClass[i].plannedquantity < 1){
                return that.$message({
                  showClose:true,
                  message:this.$t('m.enter') + this.$t('m.in.plannedquantity'),
                  type:'warning',
                  duration:1000
                })
              }
            }
          }
          that
            .$axios({
              method:'post',
              url:'/arrivalnotice/add',
              data:that.increaseForm
            })
            .then(() => {
              that.$message({
                showClose:true,
                message:that.$t('m.success'),
                type:'success',
                duration:1000
              })
              that.inCheckList = []
              that.page = 1
              that.init()
              that.dialogFormVisible1 = false
            })
        }
      })
    },
    check_num(){
      this.form.arrivalnoticeDto.ordernumber = this.form.arrivalnoticeDto.ordernumber.replace(/[\W]/g, '')
    },
    check_num_add(){
      this.increaseForm.arrivalnoticeDto.ordernumber = this.increaseForm.arrivalnoticeDto.ordernumber.replace(/[\W]/g, '')
    },
    positiveInt(key,index){
      if (this.increaseForm.arrivalnoticedetailList[index][key].toString().length === 1){
        this.$set(this.increaseForm.arrivalnoticedetailList[index], key, this.increaseForm.arrivalnoticedetailList[index][key].toString().replace(/[^1-9]/g, ''))
      } else {
        this.$set(this.increaseForm.arrivalnoticedetailList[index], key, this.increaseForm.arrivalnoticedetailList[index][key].toString().replace(/\D/g, ''))
      }
    },
    positiveInt2(key,index){
      if (this.form.arrivalnoticedetailList[index][key].toString().length === 1){
        this.$set(this.form.arrivalnoticedetailList[index], key, this.form.arrivalnoticedetailList[index][key].toString().replace(/[^1-9]/g, ''))
      } else {
        this.$set(this.form.arrivalnoticedetailList[index], key, this.form.arrivalnoticedetailList[index][key].toString().replace(/\D/g, ''))
      }
    },
    editCancel(){
      this.dialogFormVisible = false
      this.dialogFormVisible2 = false
      this.init()
    },
    closeDialog(){
      this.$refs['checkForm'].resetFields()
    },
    closeAddDialog(){
      this.$refs['ruleFormAdd'].resetFields()
      this.increaseForm.arrivalnoticedetailList = [
        {
          arrivalnoticedetailid:null,
          plannedquantity:null,
          productname:'',
          productspec:'',
          productspeccode:'',
          suppliercode:null,
          expirationnum:null,
          limitationofreceipt:null
        }
      ]
    },
    getWarehouse(){
      this.$axios({
        method:'get',
        url:'/warehouse/list'
      }).then(({ data }) => {
        this.warehouse = data
      })
    },
    //获取货主列表
    getConsignor(){
      this.$axios({
        method:'get',
        url:'/consignor/list'
      }).then(({ data }) => {
        let all = data
        for (let i = 0;i < all.length;i++){
          this.consignor.push({
            id:all[i].consignorid,
            name:all[i].consignorname
          })
        }
      })
    },
    //获取供应商列表
    getSupplier(){
      this.$axios({
        method:'get',
        url:'/supplier/list'
      }).then(({ data }) => {
        this.supplier = data
      })
    },
    getWarehouseName(id){
      return this.warehouse.filter(function (item){
        return item.warehouseid === id
      })[0].warehousename
    },
    handleDelete(index){
      this.increaseForm.arrivalnoticedetailList.splice(index, 1)
    },
    editDelete(index){
      this.form.arrivalnoticedetailList.splice(index, 1)
    },
    addProduct(){
      let data = this.increaseForm.arrivalnoticeDto
      let arr = this.increaseForm.arrivalnoticedetailList
      for (let i = 0;i < arr.length;i++){
        if (!arr[i].plannedquantity){
          return this.$message(
            this.$t('m.enter') + this.$t('m.in.plannedquantity')
          )
        }
      }
      if (
        !data.consignorname ||
        !data.ordernumber ||
        !data.warehouseid ||
        !data.suppliername ||
        !data.typeid
      ){
        return this.$message(this.$t('m.notice.info'))
      } else {
        this.increaseForm.arrivalnoticedetailList.push({
          arrivalnoticedetailid:null,
          plannedquantity:null,
          productname:'',
          productspec:'',
          productspeccode:'',
          suppliercode:null
        })
      }
    },
    editAddProduct(){
      let data = this.form.arrivalnoticeDto
      let arr = this.form.arrivalnoticedetailList
      for (let i = 0;i < arr.length;i++){
        if (!arr[i].plannedquantity){
          return this.$message(
            this.$t('m.enter') + this.$t('m.in.plannedquantity')
          )
        }
      }
      if (
        !data.consignorname ||
        !data.ordernumber ||
        !data.warehouseid ||
        !data.suppliername ||
        !data.typeid
      ){
        return this.$message(this.$t('m.notice.info'))
      } else {
        this.form.arrivalnoticedetailList.push({
          //一次添加一条，添加多条再加一个数组项
          arrivalnoticedetailid:null,
          plannedquantity:null,
          productname:'',
          productspec:'',
          productspeccode:'',
          suppliercode:null
        })
      }
    },
    func1(){
      this.blur1 = true
    },
    getSkuBlur(index, form){
      this.getSku(index, form)
    },
    getSkuEnter(index, form){
      this.blur1 = false
      this.getSku(index, form)
    },
    getSku(index, form){
      let that = this
      that.isClick = true
      that.code =
        form.arrivalnoticedetailList[index].productspeccode
      //console.log(that.code);
      let arr = form.arrivalnoticedetailList
      for (let i = 0;i < arr.length;i++){
        if (i !== index){
          if (
            arr[i].productspeccode ===
            form.arrivalnoticedetailList[index].productspeccode
          ){
            form.arrivalnoticedetailList.pop()
            return that.$message(that.$t('m.notice.exist'))
          }
        }
      }
      if (that.code){
        that
          .$axios({
            method:'get',
            url:`/productinfo/sku?sku=${that.code}`
          })
          .then(({ data }) => {
            if (data.productSkuList[0].skustate === 1){
              that.isClick = false
              form.arrivalnoticedetailList[index].isexpiration =
                data.productdto.isexpiration
              form.arrivalnoticedetailList[
                index
              ].limitationofreceipt = data.productdto.limitationofreceipt
              form.arrivalnoticedetailList[index].expirationnum =
                data.productdto.expirationnum
              //处理返回的数据suppliercode为null的情况，设置suppliercode为空
              let suppliercode = data.productSkuList[0].suppliercode ? data.productSkuList[0].suppliercode : null
              let productname = data.productdto.productname
              let fullspec = data.productSkuList[0].fullspec
              let productid = data.productdto.productid

              form.arrivalnoticedetailList[
                index
              ].suppliercode = suppliercode
              form.arrivalnoticedetailList[
                index
              ].productspec = fullspec
              form.arrivalnoticedetailList[
                index
              ].productname = productname
              form.arrivalnoticedetailList[
                index
              ].productid = productid
            } else {
              that.$message({
                showClose:true,
                message:that.$t('m.notice.cannot'),
                type:'warning',
                duration:1500
              })
            }
          }).catch(() => {
            form.arrivalnoticedetailList[index].productspeccode = ''
            form.arrivalnoticedetailList[index].suppliercode = null
            form.arrivalnoticedetailList[index].productname = ''
            form.arrivalnoticedetailList[index].productspec = ''
            form.arrivalnoticedetailList[index].plannedquantity = null
          })
      }
    },
    checkDate(){
      if (this.formInline.enddate && this.formInline.startdate){
        if (this.formInline.enddate < this.formInline.startdate){
          this.$message({
            showClose:true,
            message:this.$t('m.check.date'),
            type:'warning',
            duration:1000
          })
          setTimeout(() => {
            this.formInline.enddate = ''
          }, 0)
        }
      }
    },
    setType(id){
      this.increaseForm.arrivalnoticeDto.typeid = id
      this.increaseForm.arrivalnoticeDto.typename = this.arrivaltype.filter(
        function (item){
          return item.value === id
        }
      )[0].label

      this.form.arrivalnoticeDto.typeid = id
      this.form.arrivalnoticeDto.typename = this.arrivaltype.filter(function (
        item
      ){
        return item.value === id
      })[0].label
    },
    setSupplier(id){
      this.increaseForm.arrivalnoticeDto.supplierid = id
      this.increaseForm.arrivalnoticeDto.suppliername = this.supplier.filter(
        function (item){
          return item.supplierid === id
        }
      )[0].suppliername
      this.form.arrivalnoticeDto.supplierid = id
      this.form.arrivalnoticeDto.suppliername = this.supplier.filter(function (
        item
      ){
        return item.supplierid === id
      })[0].suppliername
    },
    setConsignor(id){
      this.increaseForm.arrivalnoticeDto.consignorid = id
      this.increaseForm.arrivalnoticeDto.consignorname = this.consignor.filter(
        function (item){
          return item.id === id
        }
      )[0].name
      this.form.arrivalnoticeDto.consignorid = id
      this.form.arrivalnoticeDto.consignorname = this.consignor.filter(function (
        item
      ){
        return item.id === id
      })[0].name
    },
    // 理货
    toSign(){
      if (this.tableRowSelected.length === 0) return this.callbackMessage(`${this.$t('m.choose')}${this.$t('m.sigin.noticesigin')}`)
      if ([1,2,6,7,20].includes(this.tableRowSelected[0].state)){
        this.callbackMessage(`${this.$t('m.choose')}${this.$t('m.sigin.checked')}`)
      } else {
        let { noticenumber } = this.tableRowSelected[0]
        this.$router.push({ path:'sign', query:{ noticenumber } })
      }
    },
    // 确认到货
    clickConfirm(){
      if (this.tableRowSelected.length > 0){
        // 1 待审核 2 不通过 3 已审核 4 待签收 5 部分理货 6全部理货 7.已完成
        if (this.tableRowSelected[0].state === 6||this.tableRowSelected[0].state === 5){
          this.opt = 'confirm'
          this.row = this.tableRowSelected[0]
          this.arrivalOpen(this.row)
        } else {
          this.$message({
            showClose:true,
            message:this.$t('m.choose') + this.$t('m.sigin.sigined'),
            type:'warning',
            duration:1000
          })
        }
      } else {
        this.$message({
          showClose:true,
          message:this.$t('m.choose') + this.$t('m.in.noticenumber'),
          type:'warning',
          duration:1000
        })
      }
    },
    confirm(){
      this.$axios({
        method:'put',
        url:`/arrivalnotice/confirmarrivalnotice/${this.row.arrivalnoticeid}`
      }).then(() => {
        this.dialogFormVisible3=false
        this.$message.success(this.$t('m.quality.confirmsuccess'))
        this.init()
        setTimeout(() => {
          this.printPdf(this.row)
        }, 1000)
      })
    },
    // 取消通知单
    clickCancel(){
      if(!this.tableRowSelected.length) return this.callbackMessage(this.$t('m.arrivalnotice.choose'))
      if(this.tableRowSelected[0].state !== 20){
        if(this.tableRowSelected[0].state !== 1&&this.tableRowSelected[0].state !== 3) return this.callbackMessage(this.$t('m.arrivalnotice.noCancel'))
        this.$confirm(this.$t('m.arrivalnotice.cancelConfirm'), this.$t('m.noticemessage'), {
          confirmButtonText:this.$t('m.confirm'),
          cancelButtonText:this.$t('m.cancel'),
          center:true,
          type:'warning'
        }).then(() => {
          let options = {
            method:'put',
            url:`arrivalnotice/cancel/${this.tableRowSelected[0].arrivalnoticeid}`
          }
          this.btnLoading = false
          this.$axios(options).then(() => {
            this.$message({
              type:'success',
              message:this.$t('m.arrivalnotice.cancelSuccess')
            })
            this.init()
          })
        }).catch(() => {
          this.btnLoading = false
        })
      }else{
        return this.callbackMessage(this.$t('m.arrivalnotice.cancelled'))
      }
    },
    // 查看理货结果按钮
    triggerSigning(index, row){
      let completed = true
      let noticenumber = this.activeNoticenumber
      let { productspeccode:sku, actualquantity } = row
      this.arrivalnoticeArg = { noticenumber, sku, actualquantity, completed }
      this.signingAddPopupVisible = true
    },
    print(){
      if (this.tableRowSelected.length > 0){
        let LODOP = getLodop()
        this
          .$axios({
            method:'post',
            url:'/printtemplate/query',
            data:{
              ids:[this.tableRowSelected[0].arrivalnoticeid],
              templateName:'arrivalnotice'
            }
          })
          .then(({ data }) => {
            let printContent = data
            eval(printContent)
            LODOP.SET_PRINT_PAGESIZE(1, '50mm', '30mm', '')
            LODOP.PREVIEW()
          })
      } else {
        this.$message({
          showClose:true,
          message:this.$t('m.chooseprint') + this.$t('m.in.noticenumber'),
          type:'warning',
          duration:1000
        })
      }
    },
    printPdf(row){
      let { arrivalnoticeid } = row
      let routeData = this.$router.resolve({
        name:'print'
      })
      let storageData = {
        arrivalnoticeid,
        token:this.$store.state.basicInfo.userInfo.token,
        warehousename:this.$store.state.basicInfo.warehouseInfo.name
      }
      localStorage.setItem('storageData', JSON.stringify(storageData))
      window.open(routeData.href, '_blank')
    },
    // 1 待审核 2 不通过 3 已审核 4 待签收 5 部分理货 6全部理货 7.已完成 20.已取消
    options(state){
      let result = [
        {value:'',label:this.$t('m.all')},
        {value:1,label:this.$t('m.in.state1')},
        {value:2,label:this.$t('m.in.state2')},
        {value:3,label:this.$t('m.in.state6')},
        {value:4,label:this.$t('m.in.state7')},
        {value:5,label:this.$t('m.in.state4')},
        {value:6,label:this.$t('m.in.state10')},
        {value:7,label:this.$t('m.in.state11')},
        {value:20,label:this.$t('m.in.state20')}
      ].find((item) => item.value === state)
      return result ? result .label : ''
    }
  },
  activated(){
    this.init()
    this.getWarehouse()
    // let arr=this.$store.state.basicInfo.menuTag.map((v)=>{
    //   return v.route
    // })
    // let index=arr.indexOf(this.$route.path.substring(5))
    // if(index<0){
    //   this.formInline={}
    // }
  },
  beforeRouteLeave(to, form, next){
    this.dialogFormVisible=false
    this.dialogFormVisible1=false
    this.dialogFormVisible2=false
    this.dialogFormVisible3=false

    // 关闭页面，清空查询条件
    // let arr=this.$store.state.basicInfo.menuTag.map((v)=>{
    //   return v.route
    // })
    // let index=arr.indexOf(this.$route.path.substring(5))
    // if(index<0){
    //   this.formInline={}
    // }
    next()
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style  lang="scss" scoped>
.el-table td,
.el-table th.is-leaf {
  border-bottom: none;
}
.el-form {
  width: 100%;
}
.el-input,
.el-form-item__content {
  width: 100%;
}
.el-input--mini {
  padding-right: 15px;
}
.el-select {
  display: block;
}
.el-radio > span {
  font-size: 10px;
}
.el-input--mini {
  padding-right: 0;
}
</style>
